package com.fbt.andon.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fbt.andon.domain.BoardStation;
import com.fbt.andon.domain.Days;
import com.fbt.andon.domain.Task;
import com.fbt.andon.service.impl.DaysServiceImpl;

import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeoutException;

/**
 * 每日产量Controller
 *
 * @author fengtao
 * @date 2021-08-13
 */
@RestController
@RequestMapping("/days")
@Api(description = "每日生产api")
public class DaysController extends BaseController {
    @Autowired
    private DaysServiceImpl daysService;


    //@PreAuthorize(hasPermi = "mes:andon:query")
    @GetMapping("/query")
    @ApiOperation("查询每日产量")
    public AjaxResult findIssueList() {
        startPage();
        return AjaxResult.success("查询成功", daysService.list(null));
    }


    //@PreAuthorize(hasPermi = "mes:andon:query")
    @GetMapping("/queryByDay")
    @ApiOperation("查询近7日产量")
    public AjaxResult findByDays() {
        startPage();
        QueryWrapper<Days> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("amount_date").last("limit 7");
        List<Days> list = daysService.list(wrapper);
        return AjaxResult.success("查询成功", daysService.list(wrapper));
    }


    //@PreAuthorize(hasPermi = "mes:andon:query")
    @GetMapping("/dimQuery")
    @ApiOperation("根据产线名模糊查询产线信息")
    public AjaxResult list(String lineName) {
        startPage();
        QueryWrapper<Days> wrapper = new QueryWrapper<>();
        wrapper.like("line_name", lineName);
        return AjaxResult.success("查询成功", daysService.list(wrapper));
    }


    //@PreAuthorize(hasPermi = "mes:andon:query")
    @GetMapping(value = "/get/{id}")
    @ApiOperation("获取每日产量详细信息，参数id")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success("获取成功", daysService.getById(id));
    }


    //@PreAuthorize(hasPermi = "mes:andon:add")
    @ApiOperation("新增每日产量，参数days")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Days days) {
        return AjaxResult.success("新增成功", daysService.save(days));
    }


    //@PreAuthorize(hasPermi = "mes:andon:edit")
    @ApiOperation("修改每日产量，参数days")
    @PostMapping("/updateById")
    public AjaxResult edit(@RequestBody Days days) {
        return AjaxResult.success("修改成功", daysService.updateById(days));
    }


    //@PreAuthorize(hasPermi = "mes:andon:remove")
    @ApiOperation("批量删除每日产量，参数ids")
    @PostMapping("/deletes/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return AjaxResult.success("删除成功", daysService.removeByIds(Arrays.asList(ids)));
    }


//    //@PreAuthorize(hasPermi = "mes:andon:remove")
    @ApiOperation("testS")
    @PostMapping("/feng")
    public void feng() throws IOException, TimeoutException {
        daysService.RunMQConsume();
    }

}
